package starcoast.bocai.com.starcoast.activitys.work;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import android.view.View;

import com.flyco.tablayout.SlidingTabLayout;

import java.util.ArrayList;

import butterknife.Bind;
import butterknife.ButterKnife;
import starcoast.bocai.com.starcoast.R;
import starcoast.bocai.com.starcoast.common.BaseActivity;
import starcoast.bocai.com.starcoast.fragments.MemorCompleteFrament;
import starcoast.bocai.com.starcoast.fragments.MemorUnCompleteFrament;
import starcoast.bocai.com.starcoast.fragments.holiday.AllHolidayFragment;
import starcoast.bocai.com.starcoast.fragments.holiday.DoneHolidayFragment;
import starcoast.bocai.com.starcoast.fragments.holiday.NoApprovalHolidayFragment;
import starcoast.bocai.com.starcoast.fragments.holiday.NoDoneHolidayFragment;
import starcoast.bocai.com.starcoast.view.ViewFindUtils;

/**
 * Created by admin on 2016/6/14.
 */
public class HolidayActivity extends BaseActivity {
    private ArrayList<Fragment> mFragments = new ArrayList<>();
    private final String[] mTitles = {
            "全部", "待审批","未通过","已通过"
    };
    private MyPagerAdapter mAdapter;
    @Bind(R.id.holiday_tab)
    SlidingTabLayout holiday_tab;
    @Bind(R.id.toolbar)
    Toolbar toolbar;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_holiday);
        ButterKnife.bind(this);
        initToolbar("请假列表");
        initToolBack();
        toolbar.inflateMenu(R.menu.menu_add);
        toolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
            @Override
            public boolean onMenuItemClick(MenuItem item) {
                startActivity(new Intent(HolidayActivity.this, AddHolidayActivity.class));
                return false;
            }
        });
        initView();
    }
    private void initView(){
        mFragments.add(new AllHolidayFragment());
        mFragments.add(new NoApprovalHolidayFragment());
        mFragments.add(new NoDoneHolidayFragment());
        mFragments.add(new DoneHolidayFragment());
        View decorView = getWindow().getDecorView();
        ViewPager vp = ViewFindUtils.find(decorView, R.id.vp);
        mAdapter = new MyPagerAdapter(getSupportFragmentManager());
        vp.setAdapter(mAdapter);
        holiday_tab.setViewPager(vp);
        vp.setCurrentItem(0);
    }
    private class MyPagerAdapter extends FragmentPagerAdapter {
        public MyPagerAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public int getCount() {
            return mFragments.size();
        }

        @Override
        public CharSequence getPageTitle(int position) {
            return mTitles[position];
        }

        @Override
        public Fragment getItem(int position) {
            return mFragments.get(position);
        }
    }
}
